package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.Status;
import com.vne.skyemart.service.StatusService;

@Controller
@SessionAttributes
@RequestMapping("/status")
public class StatusController {

	@Autowired
	private StatusService statusService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveStatus(@ModelAttribute(" status") Status status,
			BindingResult result) {
		statusService.addStatus(status);
		return new ModelAndView("redirect:/status.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listStatus(Model model) {
		model.addAttribute("status",  statusService.listStatus());

		return "statusList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addStatus(@ModelAttribute("status") Status status,
			BindingResult result) {
		return new ModelAndView("addStatus");
	}

}